<?php
/*
	Rss-aggregator php script : Aggregate rss feeds to display it as needed
	Visit http://www.rss-aggregator.com for more help.
	Copyright (C) 2008 DAHU.FR

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

	$warning = '';
	$droitconfig = '';
	$install = '';
	
	if (isset($_REQUEST["Installer"]) && !empty($_REQUEST["ServBD"]) && !empty($_REQUEST["LoginBD"]) && !empty($_REQUEST["PswBD"]) && !empty($_REQUEST[
	"NomBD"]) && !empty($_REQUEST["URLrssa"]) && !empty($_REQUEST["FormatDate"]))
	{
		$ServBD = $_REQUEST["ServBD"];
		$LoginBD = $_REQUEST["LoginBD"];
		$PswBD = $_REQUEST["PswBD"];
		$NomBD = $_REQUEST["NomBD"];
		$URLrssa = $_REQUEST["URLrssa"];
		$FormatDate = $_REQUEST["FormatDate"];
		
		@$connexion = mysql_connect ($ServBD, $LoginBD, $PswBD);
		if (!$connexion)
		{
			$warning = "Sorry, connection to '" . $ServBD . "' server is impossible\n";
		}
		else
		{
			$selectBD = mysql_select_db($NomBD);
			if ($selectBD == '')
			{
				$warning = "Sorry, access to the '" . $NomBD . "' data base impossible\n";
			}
			// Spécifie l'encodage UTF-8 pour dialoguer avec la BD
			mysql_query("SET NAMES utf8");
		}
	}
	
		// Si la connexion au serveur et à la base de donnée est faite
	if ($connexion && $selectBD == '1')
	{
		$requete1 = "SELECT CONid FROM RSSAconfig";
		$resultat1 = mysql_query ($requete1, $connexion);
		if ($resultat1)
		{
			$warning = 'The installation is impossible because it was already done.';
		}
		else
		{
		
			$chemin = $_REQUEST['NomChemin'];
			$PswAdmin = $_REQUEST['PswAdmin'];
			$CONrafraich = $_REQUEST['TpsRafraich']*60;
			$URLrssa = $_REQUEST['URLrssa'];
			$FormatDate = $_REQUEST['FormatDate'];
			$langue = $_REQUEST['Langue'];
			
			if (@fopen($chemin.'/admin/fonctions/config.php','w'))
			{
				$droitconfig = 'OK';
				
				$file_content = file($chemin.'/admin/rss-aggregator.sql');
				foreach($file_content as $sql_line)
				{
					if(trim($sql_line) != "" && strpos($sql_line, "--") === false)
					{
						mysql_query($sql_line);
					 }
				}
			
				$contenu = "<?php
/*
	Rss-aggregator php script : Aggregate rss feeds to display it as needed
	Visit http://www.rss-aggregator.com for more help.
	Copyright (C) 2008 DAHU.FR

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
	
	define ('SERVER_BD', '$ServBD');
	define ('LOGIN_BD', '$LoginBD');
	define ('PASS_BD', '$PswBD');
	define ('NAME_BD', '$NomBD');
	
	\$PswAdmin = '$PswAdmin';
	
	\$CHEMIN = '$chemin';
	
	\$URLRSSA = '$URLrssa';
	
	\$DATEFORMAT = '$FormatDate';	// PHP date() 
	
	\$LANGUAGE= '$langue';	// en = default , other langage = 'other' = mean that the date use the array's lesjours and lesmois below. You can edit the html in display.php line 73.
	
	\$lesjours = array('Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam');
	\$lesmois = array('', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai','Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
?>";
				
				$fichier = fopen($chemin.'/admin/fonctions/config.php',"w");
				fwrite($fichier, $contenu);
				fclose($fichier);
				
				$requete1 = "INSERT INTO RSSAconfig (CONrafraich) VALUES ('$CONrafraich')";
				$resultat1 = mysql_query ($requete1, $connexion);
				
				header('location: ./admin/index.php');
			}
			else
			{
				$warning = 'rssa/admin/fonctions/config.php is not writable, please chmod it 777';
			}
		}
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="author" content="Gaston BOUCHAYER" />
	<meta name="keywords" content="" />
	<meta name="description" content="" />
		<title>RSS-aggregator.com : Feeds aggregator for webmasters - Install</title>
	<link href="feuille.css" rel="stylesheet" type="text/css" />
	<style type="text/css">
	body {
		width: 400px;
		margin: auto;
		font-family: Verdana, sans-serif;
		font-size: 12px;
	}
	div.logo {
		width : 300px;
		margin: auto;
	}
	div.principale {
		width: 400px;
		margin: auto;
		border: #990099 1px solid;
		padding: 20px;
	}
	div.titre {
		font-size: 18px;
		font-weight: bold;
		text-align: center;
	}
	div.erreur {
		font-size: 16px;
		color: #FF0000;
		text-align: center;
	}
	div.bouton {
		float: right;
	}
	</style>
</head>


<body lang="fr" xml:lang="fr" >


<div class="logo">
	<br />
	<img src="admin/logo.jpg" />
</div>
<br />

<div class="principale">	<!-- DIV PRINCIPALE -->

<div class="titre" > Install of RSS-Aggregator : </div>
<br />

<?php
	// Si la connexion au serveur ou à la base de données n'est pas faite
	if (!$connexion || $selectBD == '' || $droitconfig == '')
	{
		$chemin = realpath(dirname(__FILE__));
		$URLrssa = str_replace('/install.php', '', 'http://'.$_ENV["SERVER_NAME"].$_ENV["REQUEST_URI"]);
		$FormatDate = 'D F j, y';
?>
		<br />
		<div class="erreur"> <?php echo $warning; ?> </div>
		<br />
		
		<form action="install.php" method="post" onsubmit="return verif()">
			<label> Server name of the data base :
				<input type="text" name="ServBD" id="ServBD" value="<?php echo $ServBD; ?>" />
			</label> <br />
			<label> Login of the data base :
				<input type="text" name="LoginBD" id="LoginBD" value="<?php echo $LoginBD; ?>" />
			</label> <br />
			<label> Password of the data base :
				<input type="text" name="PswBD" id="PswBD" value="<?php echo $PswBD; ?>" />
			</label> <br />
			<label> Name of the data base :
				<input type="text" name="NomBD" id="NomBD" value="<?php echo $NomBD; ?>" />
			</label> <br />
			<label> Password for admin access :
				<input type="password" name="PswAdmin" id="PswAdmin" />
			</label> <br />
			<label> Absolute path :
				<input type="text" name="NomChemin" id="NomChemin" value="<?php echo $chemin; ?>" />
			</label> <br />
			<label> URL of rssa directory (no trailing slash) :
				<input type="text" name="URLrssa" id="URLrssa" value="<?php echo $URLrssa; ?>" />
			</label> <br />
			<label> PHP date format :
				<input type="text" name="FormatDate" id="FormatDate" value="<?php echo $FormatDate; ?>" />
			</label> (ex :  <?php echo date('D F j, y'); ?>)<br />
			<label> Language :
				<select name="Langue" id="Langue" >
					<option value="en" > en </option>
					<option value="other" > other </option>
				</select>
			</label> <br />
			<label> Refresh time :
				<input type="text" name="TpsRafraich" id="TpsRafraich" size="3" value="60" />min
			</label> <br />
			<div class="bouton"> <input type="submit" name="Installer" id="Installer" value="Install" /> </div>
		</form>
		
		<script type="text/javascript">
		<!--
			// Fonction qui sert à vérifier que les champs ne sont pas vides
			function verif()
			{
				if (document.getElementById("ServBD").value == "")
				{
					alert("Error : \"Server name of the data base\" is empty");
					return false;
				}
				if (document.getElementById("LoginBD").value == "")
				{
					alert("Error : \"Login of the data base\" is empty");
					return false;
				}
				if (document.getElementById("PswBD").value == "")
				{
					alert("error : \"Password of the data base\" is empty");
					return false;
				}
				if (document.getElementById("NomBD").value == "")
				{
					alert("Error : \"Name of the data base\" is empty");
					return false;
				}
				if (document.getElementById("PswAdmin").value == "")
				{
					alert("Error : \"Password for admin access\" is empty");
					return false;
				}
				if (document.getElementById("NomChemin").value == "")
				{
					alert("Error : \"Absolute path\" is empty");
					return false;
				}
				if (document.getElementById("URLrssa").value == "")
				{
					alert("Error : \"URL of rssa directory\" is empty");
					return false;
				}
				if (document.getElementById("TpsRafraich").value == "")
				{
					alert("Error : \"Refresh time\" is empty");
					return false;
				}
				else return true
			}
		-->
		</script>
<?php
	}
?>

</div> <!-- FIN DIV PRINCIPALE -->

</body>
</html>